//
//  ItemVC2TableViewCell.m
//  喜马拉雅FM
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 lanou.com. All rights reserved.
//
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
 


#import "ItemVC2TableViewCell.h"
#import "ModelForListen.h"
#import "UIImageView+WebCache.h"

#import "DataBaseHandler.h"

@interface ItemVC2TableViewCell ()

@property (nonatomic, retain) UIImageView *pictureImageView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *contentLabel;
@property (nonatomic, retain) UIButton *collectButton;
@property (nonatomic, assign) BOOL isOK;

@end

@implementation ItemVC2TableViewCell

- (void)dealloc {

    [_pictureImageView release];
    [_titleLabel release];
    [_contentLabel release];
    [_collectButton release];
    [super dealloc];

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];

    }
    return self;
}

- (void)createSubViews {

    self.pictureImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"2.jpg"]];
    self.pictureImageView.frame =  CGRectMake(10, 10, 80, 80);
    [self.contentView addSubview:self.pictureImageView];
    [self.pictureImageView release];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 10, WIDTH - 100 - 50, 30)];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.titleLabel release];
    
    self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 50, WIDTH - 100 - 50, 30)];
    [self.contentView addSubview:self.contentLabel];
    self.contentLabel.textColor = [UIColor grayColor];
    [self.contentLabel release];
    
    
//    self.collectButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.collectButton.frame = CGRectMake(WIDTH - 50, 34, 32, 32);
//    [self.contentView addSubview:self.collectButton];
//    [self.collectButton setImage:[UIImage imageNamed:@"kong"] forState:UIControlStateNormal];
//    [self.collectButton addTarget:self action:@selector(handleShouCang:) forControlEvents:UIControlEventTouchUpInside];
//    [self.collectButton setTintColor:[UIColor grayColor]];
  
    
}

- (void)handleShouCang:(UIButton *)button {

  self.isOK = !self.isOK;
    if (self.isOK) {

        [self.collectButton setTintColor:[UIColor orangeColor]];

      
    }else {
        
        [self.collectButton setTintColor:[UIColor grayColor]];
    }
  


}

- (void)passModelForListen:(ModelForListen *)model {

    self.titleLabel.text = model.title;
    [self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:model.coverSmall] placeholderImage:[UIImage imageNamed:@"2.jpg"]];
    self.contentLabel.text = model.nickname;
    
}

- (void)passCollectModel:(ModelForListen *)model {

     self.titleLabel.text = model.title;
    
    // 判断数据库中的某个属性是否为(null);
    // [NSNull null]返回一个null的对象.
    
//    NSString *str = model.lastUptrackTitle;
//
//    NSString *str2 = @"";
//    
//    NSLog(@"**********%@", str2);
//    
//    NSLog(@"=========%@",model.lastUptrackTitle);
//    if ([str isEqualToString:@"(null)"])
//    {
//        NSLog(@"dddddd");
//    }else {
//    
//        NSLog(@"aaaaaaa");
//    }
//

//    NSLog(@"-------%d",[model.coverLarge isEqual:[NSNull null]]);
    
    // 数据库中若没有给属性赋值,那么系统会给它一个(null),此值不为空.
    if ([model.coverSmall isEqualToString:@"(null)"]) {
                       // 是首页.
        [self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:model.coverLarge] placeholderImage:[UIImage imageNamed:@"2.jpg"]];
        self.contentLabel.text = model.trackTitle;
        
    }else {
          // 非首页.
        [self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:model.coverSmall] placeholderImage:[UIImage imageNamed:@"2.jpg"]];
      
        if ([model.lastUptrackTitle isEqualToString:@"(null)"]) {
            
              self.contentLabel.text = model.nickname;
           
        }else {
         self.contentLabel.text = model.lastUptrackTitle;
          
        }
          }
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
